<!DOCTYPE html>
<html>
    <head>
       <?php include 'browser_detect.php';
          $googleURL = "/gsearch";
          $bingURL = "/bsearch";
          if (isMobile()) { 
           $googleURL = "/gsearch";
           $bingURL = "/bmsearch";
          ?>
        <meta name="HandheldFriendly" content="true" />
        <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
          <?php } ?>
              
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
        <meta name="title" content="One Search" />
        <meta name="keywords" content='<?php echo $_GET["q"]; ?>' />
        <meta name="description" content=" The best search tool. Search Once, you can get results from both google and bing side by side with 
              the same item highlighted.Google vs Bing  <?php echo $_GET["q"]; ?>  " />

        <script src="//www.google.com/jsapi" type="text/javascript"></script>
        <script type="text/javascript">
            google.load('search', '1');

            function inputFocus() {
                document.getElementById('searchText').style['background'] = '';
            }

            function inputBlur() {
                var queryInput = document.getElementById('searchText');
                if (!queryInput.value) {
                    queryInput.style['background'] =
                        'white url(http://www.google.com/coop/images/'
                        + 'google_custom_search_watermark.gif) no-repeat 0% 50%';
                }
            }

            function init() {
                //var cx = '011152833664020937705:ytiupixbdcs';
                google.search.CustomSearchControl.attachAutoCompletion(
                '006146382722072746140:rc7_dtmydr0',
                //'011152833664020937705:ytiupixbdcs',
                document.getElementById('searchText'),
                'searchForm');
                inputBlur();
            }

            function submitQuery() {
                window.location = '/html/two_page_search_results.html?q='
                    + encodeURIComponent(
                document.getElementById('searchText').value);
                return false;
            }

            google.setOnLoadCallback(init);
        </script>
        
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
        <script type="text/javascript" src="/wordlist/js/jquery.cookie.js"></script>
         <!-- <script src="http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js"></script> -->
        <script>
            //alert(1);
            $(document).ready(function() {
                //alert(2);
                //alert($(document).width());
                $("#frame").width($(document).width()/2-20);
                $("#bframe").width($(document).width()/2-20);
                //alert( $.cookie("hideItem"));
                 $("#hide_google").attr("checked",  $.cookie("hideItem") == "google");
                 $("#hide_bing").attr("checked",  $.cookie("hideItem") == "bing");

                $("#hide_google").bind("click", function() {
                       
                     if ($(this).attr('checked')) {
                       $("#hide_bing").attr('checked', false);
                       $.cookie("hideItem", "google", { expires:365});
                     } else {
                         $.cookie("hideItem", "");
                      }
                    itemManage();
                });
               $("#hide_bing").bind("click", function() {
                   if ($(this).attr('checked')) {
                     $("#hide_google").attr('checked', false);
                     $.cookie("hideItem", "bing", { expires:365});
                    }  else {
                         $.cookie("hideItem", "");
                      }
                    itemManage();
                });

            }
          );
            $(window).resize(function() {
                $("#frame").width($(document).width()/2-20);
                $("#bframe").width($(document).width()/2-20);
                

            }
        );

        </script>

        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-9033082-2']);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();

        </script>
    </head>

    <body>
           
        <?php  if (!isMobile()) { ?>
        <h1 align="center"> One Search Gets Both Results from <span style="color: brown" > Google </span> and <span style="color:green"> Bing </span> </h1>
        <?php }  else { ?>
        <h3 align="center"> One Search </h3>
       
        <?php }
        $terms = array("irs", "Samsung Tablet", "Amazon Stores", "Xbox", "Kindle", "Playstation",  "iPhone",  "iPad",  "Wii",  "iPad",  "Nook",  "Windows Phone",  "Macbook Pro");
        $q = $_GET["q"];
        if ($q == null)
            $q = $terms[rand(0, count($terms)-1)];
        ?>
        <h2 align="center">
          <?php if (isMobile()) { ?>

         <script type="text/javascript"><!--
	     google_ad_client = "ca-pub-1830488441040930";
/* mobile-onesearch */
			google_ad_slot = "2290733974";
		google_ad_width = 320;
		google_ad_height = 50;
		//-->
		</script>
		<script type="text/javascript"
		src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
		</script>
     <?php } else { ?>

           <script type="text/javascript"><!--
            google_ad_client = "ca-pub-1830488441040930";
            /* wordlist */
            google_ad_slot = "4413544198";
            google_ad_width = 728;
            google_ad_height = 90;
            //-->
            </script>
            <script type="text/javascript"
                    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
            </script>
      <?php } ?>
 </h2>
        <h3 align="center"> 
            <form id="searchForm" method="GET">
                <input autocomplete="off" id="searchText" name=q type="text" value='<?php echo $q; ?>'
                  size= '<?php echo isMobile()? "20":  "60"; ?>' maxlength=250/>
                <input type="submit" value="Search" /> 
                 <?php  if (!isMobile()) {?>
                <a class="sp" onclick="window.external.AddSearchProvider('http://www.elookinto.com/onesearch/search.xml');" 
     href="#">Add to browser search</a> <?php } ?>
 <br/>
                <input id="prev" type="submit" style="display:none"  value="Prev"/>
                <input id="next" type="submit" style="display:none"  value="Next"/> 
                <span style="font-weight:normal;font-size:small; margin-left:40px"> Hide the same items in Google:
                   <input type="checkbox" id="hide_google" /> &nbsp; &nbsp; &nbsp; Bing: <input type="checkbox" id="hide_bing" /> </span>
                <input id="gq" name=gq type="hidden"  value=""/>
                <input id="bq" name=bq type="hidden"  value=""/>
            </form> </h3>

        <?php
        $gq = $_GET["gq"];
        $bq = $_GET["bq"];
        if ($gq == null || strlen($gq) == 0)
            $gq = "q=" . $q;
        else
            $gq = substr($gq, 8);
        if ($bq == null || strlen($bq) == 0)
            $bq = "q=" . $q;
        else
            $bq = substr($bq, 8);
        //echo $gq."====".$bq."<br/>";
        ?>  
        <iframe width=800 height=2000 src='<?php echo $googleURL."?".$gq; ?>'  id='frame'> </iframe>
        <iframe width=800 height=2000 src='<?php echo $bingURL."?". $bq; ?>'  id='bframe'> </iframe>

        <script>

            // Creates canvas 320 � 200 at 10, 50
            //var paper = Raphael(10, 50, 1200, 1200);
            //var c = paper.path("M10 10L90 90");
            // Creates circle at x = 50, y = 40, with radius 10
            //var circle = paper.circle(250, 340, 100);
            // Sets the fill attribute of the circle to red (#f00)
            //circle.attr("fill", "#f00");

            // Sets the stroke attribute of the circle to white
            //circle.attr("stroke", "#fff");


            function getDoc(aid)
            {

                var x=document.getElementById(aid);
                var y=(x.contentWindow || x.contentDocument);
                if (y.document)y=y.document;
                return y; 
            }     
            var delay = 1000;
            var max = 0;
            var handleAll, handleBingProc, handleGoolgeProc;
            function clearTimer(force)
            {
                //alert(max);
                if (max*1000 < delay*7 && !force) return;
                window.clearInterval(handleAll);
                window.clearInterval(handleBingProc);
                window.clearInterval(handleGoogleProc);
               
              
            }

             function itemManage() {
                                     
                    var bdoc, doc;
                    bdoc = getDoc("bframe");
                    doc = getDoc("frame");
                    var color = ["red", "orange","IndianRed", "brown", "Olive", "Magenta", "Maroon", "Coral", "DarkRed", "DarkSalmon"];
                    a1 = bdoc.getElementsByTagName("a");
                    //a2 = doc.getElementsByTagName("a");
                    a2 = $('#frame').contents().find('a').toArray();
                    t=0;
                    for (i=0; i<a1.length; i++){
                        for (j=0; j<a2.length; j++)
                        {
                            $(a1[i]).attr("target", "_blank");
                            $(a2[j]).attr("target", "_blank");
                            if ( $(a1[i]).attr("href") == $(a2[j]).attr("href") ){
                                     
                                $(a1[i]).css("color", color[t%10]);
                                $(a2[j]).css("color", color[t%10]);
                                //$(a2[j]).css("display", "none");
                                if ($("#hide_google").attr("checked"))  
                                      $(a2[j]).closest("li").css("display", "none");
                                else 
                                      $(a2[j]).closest("li").css("display", "block");

                                if ($("#hide_bing").attr("checked"))
                                      $(a1[i]).closest("li").css("display", "none");
                                else
                                      $(a1[i]).closest("li").css("display", "block");

             
                                t++;    
                            };
                        }
                    }
            }

            
            $('#bframe').ready(function(){
              
                handleAll = window.setInterval(function() {
                    max++;
                    clearTimer(false);
                    itemManage();
                    gsearch = $('#frame').contents().find('#pnnext');
                    bsearch =  $('#bframe').contents().find('.sb_pagN');

                    if (gsearch.size()>0 || bsearch.size()>0) $("#next").show();

                    gsearch = $('#frame').contents().find('#pnprev');
                    bsearch =  $('#bframe').contents().find('.sb_pagP');

                    if (gsearch.size()>0 || bsearch.size()>0) $("#prev").show();
                         
                }, delay);
                             //$('#frame').contents().find("#rhscol").html("<br/><br/><br/><br/>abc");
                            //alert($("#rhs_col").html());    
                handleBingProc = window.setInterval(function() {
                    ad = $('#bframe').contents().find('#sidebar');
                    adf = "<iframe style='border:0;padding:0px;margin:0px; margin-right:15px;margin-left:-25px'  width=250 height=640 frameBorder=0  src='/onesearch/googlead.php?q=<?php echo $_GET["q"]; ?>'> </iframe>";
                    /*ad.size() >0 && ad.html()!=adf )*/

                    ad.html(adf);
 
                    if($('#bframe').contents().find('#sw_abar').size()>0) {
                        window.clearInterval(handleBingProc);
                    }
                    $('#bframe').contents().find('.sb_adsWv2').css("display", "none");
                    $('#bframe').contents().find('#sw_abar').css("display", "none");
                    $('#bframe').contents().find('#sw_hdr').css("display", "none");
                    $('#bframe').contents().find('#sa_bop').css("display", "none");
                    $('#bframe').contents().find('#sa_bop').css("display", "none");
                    //$('#bframe').contents().find('sb_pag').css("display", "none");
                    $('#bframe').contents().find('.sb_pag').css("display", "none");
                    
                }, delay);
            });

            $('#frame').ready(function(){
                
                handleGoogleProc = window.setInterval(function() {
               
                    //  window.clearInterval(handleGoogleProc);
                    $('#frame').contents().find('#cst').css("display", "none");
                    $('#frame').contents().find('#mngb').css("display", "none");
                    //$('#frame').contents().find('#appbar').css("display", "none");
                    //$('#frame').contents().find('.mitem').css("display", "none");
                    $('#frame').contents().find('botabar').css("display", "none");
                    //$('#frame').contents().find('#tads').css("display", "none");
                    //$('#frame').contents().find('.mitem').css("display", "none");
                    $('#frame').contents().find('#gbx1').css("display", "none");
                    $('#frame').contents().find('.gbmtc').css("display", "none");
                    // $('#frame').contents().find('#gbx3').css("display", "none");
                     $('#frame').contents().find('#gbq').css("display", "none");
                    $extra = $('#frame').contents().find('#extrares').css("display", "none");
                    //$extra.css("background", "black");
                    $('#frame').contents().find('#foot').css("display", "none");
                    //$('#frame').contents().find('.gbts').css("display", "none");;
                    $('#frame').contents().find('.kl').css("display", "none");
                    var leftCol = $('#frame').contents().find('#leftnavc'); //.css("display", "none");
                     leftCol.css("display", "none");
                    leftCol.css("width", "450px");
                     leftCol.css("background", "red");

                    var centerCol =  $('#frame').contents().find('#center_col');
                     centerCol.css("margin-left", "20px"); 
                      //centerCol.css("background", "green");
                       centerCol.css("padding-right", "10px");
                     //leftNav.css("width", "width:10px");
                     //$('#frame').contents().find('#rhscol').css("display", "none");
                     var rightCol = $('#frame').contents().find('#rhscol');
                      //rightCol.html("");
                       //rightCol.css("display", "none");
                      //rightCol.css("width", "20px")
;                     //rightCol.css("height", "20px")
                      rightCol.css("background", "red");  
                       //rightCol.css("margin-left", "-50px");
                      //rightCol.css("height", "130px");
                      //$('#frame').contents().find('#rhscol').css("background", "green repeat scroll 0% 0%");
                    //var ad = $('#frame').contents().find('#rhscol');
                      var rightBlock = $('#frame').contents().find('#rhs_block');
                      var ad = rightBlock;//  $('#frame').contents().find('#leftnavc');
                      var  adf = "<iframe frameBorder=0 style='border:0;padding:0px; width:180px; height:650px' src='/onesearch/adrite2.php?q=<?php echo $_GET["q"]; ?>'></iframe>";
                      //adriteJS = ($("#adrite").html());
                     //alert(ad.html(adf));
                      if (ad.size() >0 && ad.html()!= adf ) ad.html(adf);
                      //alert(ad.html(adf));
                      //ad.css("background", "green"); 
                      //ad.css("margin-left", "10px");
                    //  $('#bframe').contents().find('#sidebar').html($("#bingad").html());
                        
                    //}
                }, delay);
                
            });


            $("#next").bind("click", function() {
                gsearch = $('#frame').contents().find('#pnnext');
                bsearch =  $('#bframe').contents().find('.sb_pagN');

                //alert(gsearch.attr("href"));
                //alert(bsearch.attr("href"));
                //alert(gsearch.size());
                if (gsearch.size()>0) 
                    $("#gq").val(gsearch.attr("href"));
                //alert(1);
                if (bsearch.size()>0)
                    $("#bq").val(bsearch.attr("href"));
                //alert($("#gq").value());
                //alert(1);
                // return false;
                //$("#searchForm").submit();
            });
                      
            $("#prev").bind("click", function() {
                gsearch = $('#frame').contents().find('#pnprev');
                bsearch =  $('#bframe').contents().find('.sb_pagP');

                //alert(gsearch.attr("href"));
                //alert(bsearch.attr("href"));
                //alert(gsearch.size());
                if (gsearch.size()>0)
                    $("#gq").val(gsearch.attr("href"));
                //alert(1);
                if (bsearch.size()>0)
                    $("#bq").val(bsearch.attr("href"));
                //alert($("#gq").value());
                //alert(1);
                // return false;
                //$("#searchForm").submit();
            });


        </script>


        <div id=adrite style="display:none">


        </div>

        <div id=g>
        </div>


           <h3 align="center"> Copyright (c) 2012, ELOOKINTO. </h3>

    </body>
</html>
